<template>
    <div>
        <router-link tag="div" to="/" class="header-back" v-show="showHeaderBack">
            <span class="iconfont icon-back">&#xe611;</span>
        </router-link>
        <div class="header" :style="opacityStyle" v-show="!showHeaderBack">
            <router-link to="/" class="header-left">
                <span class="iconfont header-left-back">&#xe611;</span>
            </router-link>
            故宫(AAAAA景区)
        </div>
    </div>
</template>
<script>
export default {
    name:"DetailHeader",
    data(){
        return{
            showHeaderBack:true,
            opacityStyle:{
                opacity: 0
            }
        }
    },
    methods:{
        handleScroll(){
            let top =document.documentElement.scrollTop;
            if(top>50){
                let opacity = top/100;
                opacity = opacity >1 ? 1 :opacity;
                this.opacityStyle={
                    opacity:opacity
                }
                this.showHeaderBack = false;
            }else{
                this.showHeaderBack = true;
            }
        }
    },
    mounted(){
        window.addEventListener('scroll',this.handleScroll)
    }
}
</script>
<style lang="stylus" scoped>
    @import '~styles/variables.styl';
    .header-back{
        position:absolute;
        top: .2rem;
        left:.2rem;
        width:.8rem;
        height:.8rem;
        line-height: .8rem
        text-align:center;
    }
</style>